package com.newenergy.light.Helper;
public class JinZhi{

//   public static void main(String args[]){
//      JinZhi t = new JinZhi();
//      String a = t.numberToHex(1);
//      System.out.println("a="+a);
//      t.numberChange(255,16);
//   }
   //把a转成指定进制
   public static String t2(int a,int n){
      String str = "";
      //1:用a去除以n，得到商和余数
      int sun = a/n;
      int yuShu = a%n;
      str = ""+shuZhiToZhiMu(yuShu);
      while(sun > 0 ){
         //2：继续用商去除以n，得到商和余数
         yuShu = sun % n;
         sun = sun / n;
         //3：如果商为0，那么就终止
         //4：把所有的余数倒序排列
         str = shuZhiToZhiMu(yuShu) + str;
      }
      System.out.println(n+"进制==="+str);
      return str;
   }
   //写一个方法实现：把一个十进制的数转换成为16进制的数
   public static String t1(int a){
      String str = "";
      //1:用a去除以16，得到商和余数
      int sun = a/16;
      int yuShu = a%16;
      str = ""+shuZhiToZhiMu(yuShu);
      while(sun > 0 ){
         //2：继续用商去除以16，得到商和余数
         yuShu = sun % 16;
         sun = sun / 16;
         //3：如果商为0，那么就终止
         //4：把所有的余数倒序排列
         str = shuZhiToZhiMu(yuShu) + str;
      }
      System.out.println("16进制==="+str);
      return str;
   }

    public static String shuZhiToZhiMu(int a){
      switch(a){
         case 10 :
            return "A";
         case 11 :
            return "B";
         case 12 :
            return "C";
         case 13 :
            return "D";
         case 14 :
            return "E";
         case 15 :
            return "F";
      }
      return ""+a;
   }
}